﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Barebones.Structure
{
    static class ReversedList
    {
        public static IEnumerable<T> AsReversed<T>(this List<T> self)
        {
            for (int i = self.Count - 1; i >= 0; --i)
                yield return self[i];
        }

        public static void ForReversed<T>(this List<T> self, Action<T> action)
        {
            // would have used AsReversed but profiling shows this is the fastest way.
            for (int i = self.Count - 1; i >= 0; --i)
                action(self[i]);
        }
    }
}
